#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;
using System.Web;
using Agresso.Interface.Layer.Service;
using System.Collections;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class SoftmarChargeTypeAccountMappingForm : Form
    {
        ChargeTypeAccountMapping m_chrgeType;
        UserControlSoftmarChargeTypeAccountMapping m_parent;
        public SoftmarChargeTypeAccountMappingForm(ChargeTypeAccountMapping chrgType, UserControlSoftmarChargeTypeAccountMapping parent)
        {
            InitializeComponent();
            this.Text = "Softmar Charge Type Account Mapping";
            m_chrgeType = chrgType;
            m_parent = parent;

            textBoxChargeType.Text = chrgType.charge_type;
            textBoxAgrAccount.Text = chrgType.chartererInv_account;
            textBoxDescription.Text = chrgType.chartererInv_account_name;
            textBoxTAx.Text = chrgType.chartererInv_tax_account;

            textBoxTCCode.Text = chrgType.tcrelet_account;
            textBoxTCDesc.Text = chrgType.tcrelet_account_name;
            textBoxTCTaxCode.Text = chrgType.tcrelet_tax_account_ovs;
            textBoxTCTaxCodeSingapore.Text = chrgType.tcrelet_tax_account_singapore;

            textBoxBTCCode.Text = chrgType.bareboatrelet_account;
            textBoxBTCDesc.Text = chrgType.bareboatrelet_account_name;
            textBoxBTCTaxCode.Text = chrgType.bareboatrelet_tax_account_ovs;
            textBoxBTCTaxCodeSinapore.Text = chrgType.bareboatrelet_tax_account_singapore;

            textBoxCRINCode.Text = chrgType.cargorelet_account_IN;
            textBoxCRINDesc.Text = chrgType.cargorelet_account_IN_name;
            textBoxCRINGST.Text = chrgType.cargorelet_account_IN_GST;

            textBoxCROUTCode.Text = chrgType.cargorelet_account_OUT_Ovs;
            textBoxCROUTDesc.Text = chrgType.cargorelet_account_OUT_Ovs_name;
            textBoxCROUTGSTOVS.Text = chrgType.cargorelet_account_OUT_Ovs_GST;
            textBoxCROUTGSTSG.Text = chrgType.cargorelet_account_OUT_SG_GST;

        }
        public SoftmarChargeTypeAccountMappingForm(string chrgType)
        {
            InitializeComponent();
            this.Text = "Softmar Charge Type Account Mapping";
            ChargeTypeAccountMappingService service = new ChargeTypeAccountMappingService();

            m_chrgeType = service.GetChargeTypeAccountMapping(chrgType);

            textBoxChargeType.Text = m_chrgeType.charge_type;
            textBoxAgrAccount.Text = m_chrgeType.chartererInv_account;
            textBoxDescription.Text = m_chrgeType.chartererInv_account_name;
            textBoxTAx.Text = m_chrgeType.chartererInv_tax_account;

            textBoxTCCode.Text = m_chrgeType.tcrelet_account;
            textBoxTCDesc.Text = m_chrgeType.tcrelet_account_name;
            textBoxTCTaxCode.Text = m_chrgeType.tcrelet_tax_account_ovs;
            textBoxTCTaxCodeSingapore.Text = m_chrgeType.tcrelet_tax_account_singapore;

            textBoxBTCCode.Text = m_chrgeType.bareboatrelet_account;
            textBoxBTCDesc.Text = m_chrgeType.bareboatrelet_account_name;
            textBoxBTCTaxCode.Text = m_chrgeType.bareboatrelet_tax_account_ovs;
            textBoxBTCTaxCodeSinapore.Text = m_chrgeType.bareboatrelet_tax_account_singapore;

            textBoxCRINCode.Text = m_chrgeType.cargorelet_account_IN;
            textBoxCRINDesc.Text = m_chrgeType.cargorelet_account_IN_name;
            textBoxCRINGST.Text = m_chrgeType.cargorelet_account_IN_GST;

            textBoxCROUTCode.Text = m_chrgeType.cargorelet_account_OUT_Ovs;
            textBoxCROUTDesc.Text = m_chrgeType.cargorelet_account_OUT_Ovs_name;
            textBoxCROUTGSTOVS.Text = m_chrgeType.cargorelet_account_OUT_Ovs_GST;
            textBoxCROUTGSTSG.Text = m_chrgeType.cargorelet_account_OUT_SG_GST;

        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                UpdateSubject();
                this.Close();
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, "Error Exception", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }

        private void UpdateSubject()
        {
            m_chrgeType.chartererInv_account = textBoxAgrAccount.Text;
            m_chrgeType.chartererInv_account_name = textBoxDescription.Text;
            m_chrgeType.chartererInv_tax_account = textBoxTAx.Text;

            m_chrgeType.tcrelet_account = textBoxTCCode.Text;
            m_chrgeType.tcrelet_account_name = textBoxTCDesc.Text;
            m_chrgeType.tcrelet_tax_account_ovs = textBoxTCTaxCode.Text;
            m_chrgeType.tcrelet_tax_account_singapore = textBoxTCTaxCodeSingapore.Text;

            m_chrgeType.bareboatrelet_account = textBoxBTCCode.Text;
            m_chrgeType.bareboatrelet_account_name = textBoxBTCDesc.Text;
            m_chrgeType.bareboatrelet_tax_account_ovs = textBoxBTCTaxCode.Text;
            m_chrgeType.bareboatrelet_tax_account_singapore = textBoxBTCTaxCodeSinapore.Text;

            m_chrgeType.cargorelet_account_IN=textBoxCRINCode.Text;
            m_chrgeType.cargorelet_account_IN_name=textBoxCRINDesc.Text;
            m_chrgeType.cargorelet_account_IN_GST = textBoxCRINGST.Text;

            m_chrgeType.cargorelet_account_OUT_Ovs = textBoxCROUTCode.Text;
            m_chrgeType.cargorelet_account_OUT_Ovs_name = textBoxCROUTDesc.Text;
            m_chrgeType.cargorelet_account_OUT_Ovs_GST = textBoxCROUTGSTOVS.Text;

            m_chrgeType.cargorelet_account_OUT_SG = textBoxCROUTCode.Text;
            m_chrgeType.cargorelet_account_OUT_SG_name = textBoxCROUTDesc.Text;
            m_chrgeType.cargorelet_account_OUT_SG_GST = textBoxCROUTGSTSG.Text;

            ChargeTypeAccountMappingService service = new ChargeTypeAccountMappingService();
            service.UpdateChargeTypeAccountMapping(m_chrgeType);
            if (m_parent != null)
                m_parent.UpdateSelectedItem(m_chrgeType);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void textBoxAgrDescription_KeyDown(object objSender, KeyEventArgs objArgs)
        {
            buttonApply.Enabled = true;
        }

        private void buttonApply_Click(object sender, EventArgs e)
        {
            try
            {
                UpdateSubject();
                buttonApply.Enabled = false;
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, "Error Exception", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }

        private void SoftmarVesselMappingForm_Load(object sender, EventArgs e)
        {
            textBoxAgrAccount.Focus();
            textBoxAgrAccount.SelectAll();
        }
    }
}